<?php
$this->pageTitle = 'Thảo luận chủ đề: ' . $announcement->title;
$this->breadcrumbs = array(
	'Thông báo' => Yii::app()->createUrl("announcement/announcement/index"),
	$announcement->title => Yii::app()->createUrl("announcement/announcement/view", array("id" => $announcement->id)),
	'Thảo luận'
);
?>
<div class="heading">
	<h1><img src="<?php echo Util::themeUrl() ?>/images/header.ico" /> Thảo luận</h1>

	<div class="controls">
		<?php
			echo CHtml::link("Trở lại trang trước", array('../announcement/announcement/index'),  array('class' => 'controls'));
			echo CHtml::link('Đăng ký thảo luận mới', array('create', 'post_id' => $announcement->id), array('class' => 'controls', 'id' => "createByPost"));
		?>
	</div>
	<div class="clear"></div>
</div>


<div class="content">
	<?php $this->widget('zii.widgets.grid.CGridView', array(
		'id'=>'comments-grid',
		'dataProvider'=>$model->search(),
		'filter'=>$model,
		'cssFile' => Util::themeUrl() . '/css/gridview.css',
		'htmlOptions'=>array('class'=>'grid-view clear'),
		'afterAjaxUpdate'=>'js:function(id,data){$.bind_data()}',
		'columns'=>array(
			array(
				'header' =>  'No.',
				'value' => '$row + Util::getPaggingIndex()',
				'htmlOptions' => array(
					'style' => 'width:25px; text-align:center'
				)
			),
			array(
			'name'	=>'content',
			'header'=>'Nội dung',
			'type'	=>'raw',
			'value'	=>'($data->parent_id != null ? str_repeat("&nbsp;", 10) : "") . (($data->highlight_mod == 1) ? CHtml::image(Util::themeUrl(). "/images/icon_new.gif") : "") . Util::markSearch($data,"content")',
			),
			array(
			'name'	=>'name',
			'header'=>'Thành viên',
			'type'	=>'raw',
			'value'	=>'Util::getUserComment($data)',
			'htmlOptions' => array(
					'style' => 'width:150px;')
			),
			array(
			'name'	=>'email',
			'header'=>'Email',
			'type'	=>'raw',
			'value'	=>'Util::markSearch($data,"email", ($data->user_id != "" && isset($data->user) ? $data->user->email : $data->email))',
			'htmlOptions' => array(
					'style' => 'width:150px;')
			),
			array(
			'name'	=>'create_at',
			'header'=>'Ngày đăng',
			'type'	=>'raw',
			'value'	=>'Util::markSearch($data,"create_at")',
			'htmlOptions' => array(
					'style' => 'width:120px;')
			),
			array(
			'name'			=>'status',
			'header'		=>'Sai phạm',
		  	'type' 			=> 'raw',
		  	'value' 		=> 'CHtml::link(CHtml::image(Util::themeUrl(). "/images/" . (($data->status==STATUS_ACTIVE)?"tick_circle.png":"cross_circle.png")), array("update", "id"=>$data->id, "returnUrl" => "index", "type"=>1))',
			'filter' 		=> Util::itemAlias('CheckComment'),
		  	'htmlOptions' 	=> array(
					'style' => 'width:60px;text-align:center',
					'id' => 'update_status',
				)
			),
			array(
				'class'=>'CButtonColumn',
				'template' => '{update}{delete}',
				'buttons'=>array(
					'update' => array (
						'label'=>'Trả lời',
						'imageUrl' => Util::themeUrl() . '/images/add2.png',
						'url'=>'Yii::app()->createUrl("comments/comments/create/", array("id"=>$data->id))',
					),
				),
				'htmlOptions' => array(
					'style' => 'width:80px;text-align:center',
				)
			),
		),
	)); ?>
</div>

<script  type="text/javascript">
	$(document).ready(function() {
		$. bind_data = function(){
			$("#comments-grid a.view").live('click', function() {
				var url = $(this).attr('href') + '?ajax=true';
				$.fancybox.open({
					href : url,
					type : 'iframe',
					afterClose: function(){
						$.fn.yiiGridView.update('comments-grid')
					}
				});
				return false;
			});

			$("#comments-grid a.delete").click(function() {
				$.ajax({
					type: "POST",
					url: url,
					success: function(data) {
						alert('Dữ liệu xóa thành công.');
						$.fn.yiiGridView.update('comments-grid');
					} //success
				});//ajax
				return false;
			});

			$("#comments-grid a.update, #createByPost").live('click', function() {
				var url = $(this).attr('href') + '?ajax=true';
				$.fancybox.open({
					href : url,
					type : 'iframe',
					minWidth: 250,
					maxWidth: 400,
					width: 400,
					afterClose: function(){
						$.fn.yiiGridView.update('comments-grid');
					}
				});
				return false;
			});
		}

		// bind data
		$. bind_data();
	});
</script>
